<?php

namespace backend\modules\statistics\models;


use common\models\business\BusinessUser;
use yii\db\ActiveRecord;
use yii\db\Query;

class UserData extends ActiveRecord
{

    public static function tableName()
    {
        return 'business_user';
    }


    public static function gender()
    {

        $gender = (new Query())->select('count(id) as num,gender')
            ->from(BusinessUser::tableName())
            ->groupBy('gender')
            ->indexBy('gender')
            ->all();
//        var_dump($gender);exit;

        $data['mannum'] = array_key_exists('男',$gender)?$gender['男']['num']:0;
        $data['womannum'] = array_key_exists('女',$gender)?$gender['女']['num']:0;

        $total =  $data['mannum']+$data['womannum'];
        $data['radioman'] = $data['mannum'] /$total;
        $data['radiowoman'] = $data['womannum']/$total;

        return $data;
    }



}